classdef DOS < Processor
  % Class for calculating Dissolved Oxygen Saturation ala SBE Data Procesing
  %
  % Author: David Goldsmith, Wash. State Dept. of Ecology, dgol461@ecy.wa.gov
  % Release date: N/A
  
    properties
      % inherited from Processor
      % inData;
      % castDT;
      % scanRate;
      % ParamID;
      % ParamDesc;
      % SBEprec;
      % EquipID;
        DBdata;
        outData;
    end
    
    methods
        function DOS = DOS(data, conn, S, T) % Constructor
            global mSB
            DOS = DOS@Processor(data);
            DOS.getDBdata(conn, 'DOS');
            if mSB, T = round2(T, 1e-4); end
            DOS.mainFormula(S, T);
        end
        
        function delete(obj) % Destructor
            % Here in case I need it
        end
        
        function mainFormula(obj, S, T)
          % Implementation verified 4/12/2012
            A = [2.00907 3.22014 4.0501 4.94457 -0.256847 3.88767];
            B = [-0.00624523 -0.00737614 -0.010341 -0.00817083];
            C = -0.000000488682;
            goodT = (-5 < T) & (T < 50);
            T(~goodT) = NaN;
            goodS = (0 < S) & (S < 60);
            S(~goodS) = NaN;
            Ts = log((298.15 - T) ./ (273.15 + T));
            obj.outData = exp(A(1) + Ts.*(A(2) + Ts.*(A(3) + Ts.*(A(4) + Ts.*(A(5) + A(6)*Ts)))) + ...
                              S.*(B(1) + Ts.*(B(2) + Ts.*(B(3) + B(4)*Ts)) + C*S));
        end
        
    end
    
end